package com.hhwy.framework.code.generation.util;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.IndexedColors;

public class ExeclStyle
{
	
    private HSSFWorkbook hwb;
    private HSSFCellStyle style0;
    private HSSFCellStyle style1;
    private HSSFCellStyle style2;
    private HSSFCellStyle style3;
    

    public ExeclStyle(HSSFWorkbook hwb)
    {
        this.hwb = hwb;
    }

    public HSSFCellStyle getStyle0() {
		return style0;
	}

	public HSSFCellStyle getStyle1()
    {
        return style1;
    }

    public HSSFCellStyle getStyle2()
    {
        return style2;
    }

    public HSSFCellStyle getStyle3()
    {
        return style3;
    }

    public ExeclStyle invoke()
    {
    	//居中
    	style0 = hwb.createCellStyle();
        // 标题样式
        style1 = hwb.createCellStyle();
        // 表头样式
        style2 = hwb.createCellStyle();
        // 内容样式
        style3 = hwb.createCellStyle();
        
        style0.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        style0.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

        // 指定单元格居中对齐
        style1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        style1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

        // 指定单元格居中对齐
        style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

        // 指定当单元格内容显示不下时自动换行
        style2.setWrapText(true);

        // 指定单元格居中对齐
        style3.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        // 指定单元格垂直居中对齐
        style3.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

        // 指定当单元格内容显示不下时自动换行
        style3.setWrapText(true);

        style1.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
        style1.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
        style1.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
        style1.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框

        // 设置边框颜色
        style1.setTopBorderColor(HSSFColor.BLACK.index);
        style1.setBottomBorderColor(HSSFColor.BLACK.index);
        style1.setLeftBorderColor(HSSFColor.BLACK.index);
        style1.setRightBorderColor(HSSFColor.BLACK.index);
        style1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中

        style2.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
        style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
        style2.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
        style2.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框

        // 设置边框颜色
        style2.setTopBorderColor(HSSFColor.BLACK.index);
        style2.setBottomBorderColor(HSSFColor.BLACK.index);
        style2.setLeftBorderColor(HSSFColor.BLACK.index);
        style2.setRightBorderColor(HSSFColor.BLACK.index);
        style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中
        // 设置边框样式
        style3.setBorderTop(HSSFCellStyle.BORDER_THIN);
        style3.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        style3.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        style3.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 设置边框颜色
        style3.setTopBorderColor(HSSFColor.BLACK.index);
        style3.setBottomBorderColor(HSSFColor.BLACK.index);
        style3.setLeftBorderColor(HSSFColor.BLACK.index);
        style3.setRightBorderColor(HSSFColor.BLACK.index);
        style3.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中

        HSSFFont font = hwb.createFont();
        font.setFontName("宋体");
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 粗体显示
        font.setFontHeightInPoints((short) 30);// 设置字体大小
        style3.setFont(font);

        HSSFFont font2 = hwb.createFont();
        font2.setFontName("宋体");
        font2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 粗体显示
        font2.setFontHeightInPoints((short) 12);

        HSSFFont font3 = hwb.createFont();
        font3.setFontName("宋体");
        font3.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);// 正常显示
        font3.setFontHeightInPoints((short) 10);

        style1.setFont(font);// 选择需要用到的字体格式
        style2.setFont(font2);// 选择需要用到的字体格式
        style3.setFont(font3);// 选择需要用到的字体格式

        HSSFCellStyle cellStyle2 = hwb.createCellStyle();

        cellStyle2.setFillForegroundColor(IndexedColors.RED.getIndex()); // 前景色

        cellStyle2.setFillPattern(CellStyle.SOLID_FOREGROUND);

        cellStyle2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中
        cellStyle2.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 指定单元格居中对齐

        cellStyle2.setFont(font3);// 选择需要用到的字体格式
        cellStyle2.setBorderTop(HSSFCellStyle.BORDER_THIN);
        cellStyle2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyle2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyle2.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 设置边框颜色
        cellStyle2.setTopBorderColor(HSSFColor.BLACK.index);
        cellStyle2.setBottomBorderColor(HSSFColor.BLACK.index);
        cellStyle2.setLeftBorderColor(HSSFColor.BLACK.index);
        cellStyle2.setRightBorderColor(HSSFColor.BLACK.index);

        HSSFCellStyle cellStyle3 = hwb.createCellStyle();

        cellStyle3.setFillForegroundColor(IndexedColors.LIME.getIndex()); // 前景色

        cellStyle3.setFillPattern(CellStyle.SOLID_FOREGROUND);

        cellStyle3.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中
        cellStyle3.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 指定单元格居中对齐

        cellStyle3.setFont(font3);// 选择需要用到的字体格式
        cellStyle3.setBorderTop(HSSFCellStyle.BORDER_THIN);
        cellStyle3.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyle3.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyle3.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 设置边框颜色
        cellStyle3.setTopBorderColor(HSSFColor.BLACK.index);
        cellStyle3.setBottomBorderColor(HSSFColor.BLACK.index);
        cellStyle3.setLeftBorderColor(HSSFColor.BLACK.index);
        cellStyle3.setRightBorderColor(HSSFColor.BLACK.index);
        return this;
    }
}